--燧发先决
local suifaxianjue = fk.CreateSkill {
    name = "mcdh_suifaxianjue",
    tags = {Skill.Compulsory}
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

suifaxianjue:addEffect(fk.EventPhaseEnd,{
    can_trigger = function(self, event, target, player, data)
        local room = player.room
        if player:hasSkill(self) and (player:getMark("mcdh_ammo") >= math.min(#lib.getPublicCards(player),3) + 2 )and target.phase == Player.Play then
            for _, p in ipairs(room:getAlivePlayers()) do
                if table.find(lib.getPublicCards(p),function(id) return Fk:getCardById(id).trueName == "slash"  end) then
                    return true
                end
            end
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        lib.LoseAmmo(player,player,math.min(#lib.getPublicCards(player),3) + 2 ,self.name)
        local n = 0
        for _, p in ipairs(room:getAlivePlayers(true)) do
            while(true) do
                local cards = table.filter(lib.getPublicCards(p), function(id) return Fk:getCardById(id).trueName=="slash" end)
                if #cards == 0  then break end
                if table.find(cards,function(id)
                    local card = Fk:getCardById(id)
                    return  #U.getDefaultTargets(p,card,true,false) > 0
                end) then
                    local use = U.askForUseRealCard(room, p, cards, ".", self.name, "#mcdh_suifaxianjue-use",  {bypass_times = true}, false, false)
                    n = n+1
                else
                    break
                end
            end
        end
        if n >= 3 then
            room.current:drawCards(3,self.name)
        end
    end
})

Fk:loadTranslationTable {
    ["mcdh_suifaxianjue"] = "燧发先决",
    [":mcdh_suifaxianjue"] = "锁定技，装填技(x+2),一名角色的出牌阶段结束时，若有角色拥有明置【杀】,你令每名角色依次使用所有明置【杀】，若共计使用至少三张【杀】，当前回合角色摸三张牌.(X为你的明置数且至多为3)",
}

return suifaxianjue